<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>审核列表(平台)</title>
    <link rel="stylesheet" type="text/css" href="/manager/easyui/themes/default/easyui.css">
    <link rel="stylesheet" type="text/css" href="easyui/themes/icon.css">
    <script type="text/javascript" src="/manager/easyui/jquery.min.js"></script>
    <script type="text/javascript" src="/manager/easyui/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="/manager/js/utils/myUtils.js"></script>
    <script type="text/javascript">
        //工具栏
        var toolbar = [{
            text: '审核',
            iconCls: 'icon-edit',
            handler: function () {
                $('#dd').dialog('open');
                let row = $("#booklist").datagrid("getSelected");
                $("#examine-book-title").text(row.title);
                // $("#examine-book-title")[0].dataset.id = row.id;
                $("#examine-book-id").val(row.id);
            }
        }];
        $(function () {
            $('#booklist').datagrid({
                title: '审核列表',
                iconCls: 'icon-save',
                url: '/manager/examine/findAll',
                columns: [
                    [
                        {field: 'title', title: '审核标题', width: 100, align: 'center'},
                        {field: 'info', title: '审核备注', width: 200, align: 'center'},  // 详情改为备注
                        {
                            field: 'flag', title: '审核状态', width: 80, align: 'center',
                            formatter: function (value, row, index) {
                                return value == "1" ? "通过" : "没通过";
                            }
                        },
                        {
                            field: 'book',
                            title: '书籍详情',
                            width: 200,
                            align: 'center',
                            formatter: function (value, row, index) {
                                return "<a href='#' onclick='showBook(" + row.id + ")'>查看</a>";
                            }
                        }
                    ]],
                toolbar: toolbar,
                pagination: true,//表示在datagrid设置分页
                pageSize: 5,
                singleSelect: true,
                pageList: [5, 10, 20]
            });


            //获取供应商数据
            $.post("/manager/supplier/findAll", rs => {
                $("#search-book-supplier-id").append("<option value=\"-1\">请选择供应商</option>");
                console.log(rs.data.length);
                console.log(rs);
                for (const r of rs.data) {
                    $("#search-book-supplier-id").append("<option value=" + r.id + ">" + r.name + "</option>");
                }
            });

            //初始化查询栏
            $("#submit_search").linkbutton({iconCls: 'icon-search', plain: true})
                .click(function () {
                    let data = {};
                    let bookname = $("#search-book-name").val();
                    let isbn = $("#search-book-isbn").val();
                    let supplierId = $("#search-book-supplier-id").val();
                    if (bookname != "") {
                        data.bookname = bookname;
                    }
                    if (isbn != "") {
                        data.isbn = isbn;
                    }
                    if (supplierId != "-1") {
                        data.supplierId = supplierId;
                    }
                    $('#booklist').datagrid("reload", data);
                });

            //初始化修改窗口 审核是否通过
            $('#dd').dialog({
                title: 'My Dialog',
                width: 700,
                height: 500,
                closed: true,
                cache: false,
                href: '',
                modal: true,
                iconCls: 'icon-save',
                buttons: [{
                    text: '提交',
                    iconCls: 'icon-ok',
                    handler: function () {
                        $.post("/manager/examine/update", $("#ff").serialize(), rs => {
                            alert(rs.msg);
                        });
                    }
                }, {
                    text: '关闭',
                    handler: function () {
                        $('#dd').dialog("close");
                    }
                }]
            });

            //添加 审核书籍对话框
            $("#show-book-id").dialog({
                title: 'My Dialog',
                width: 700,
                height: 500,
                closed: true,
                cache: false,
                modal: true,
            })
        });

        //显示单本审核书籍信息信息
        function showBook(id) {
            console.log("显示书籍信息" + id);
            $("#show-book-id").dialog("open");

            $.post("/manager/examine/findOne", {id: id}, rs => {
                console.log(rs);
                $("#show-book-name").textbox("setValue", rs.data.book.bookname);
                $("#show-book-isbn").textbox("setValue", rs.data.book.isbn);
                $("#show-book-price").textbox("setValue", rs.data.book.price);
                $("#show-book-num").textbox("setValue", rs.data.number);
                $("#show-book-group-price").textbox("setValue", rs.data.book.groupprice);
                $("#show-book-bookintroduce").textbox("setValue", rs.data.book.bookintroduce);
                $("#show-book-authorintroduce").textbox("setValue", rs.data.book.authorintroduce);

                let imgurl = rs.data.book.imgurl;
                imgurl = imgurl.indexOf("http") == 0 ? imgurl : "/manager/" + imgurl;
                $("#show-img-id").attr("src", imgurl);

            })
        }
    </script>
</head>
<body>
<form name="searchform" method="post" action="" id="searchform">
    <td width="70" height="30"><strong>审核查询：</strong></td>
    <td height="30">
        <input type="text" name="keyword" id="search-book-name" size=20 placeholder="书籍名称"/>
        <input type="text" name="keyword" size=20 id="search-book-isbn" placeholder="ISBN"/>
        <select name="search_type" id="search-book-supplier-id">
        </select>
    </td>
    <td>
        <button type="button" id="submit_search">查询</button>
    </td>
</form>
<table id="booklist"></table>
<div id="dd">
    <div align="center" style="margin-top: 30px">
        <form id="ff" method="post">
            <table>
                <tr>
                    <input id="examine-book-id" name="id" type="hidden">
                    <td>审核标题</td>
                    <td id="examine-book-title"></td>
                </tr>
                <tr>
                    <td>
                        审核状态:
                    </td>
                    <td>
                        <select name="flag" id="search_type2" style="width:100px">
                            <option value="1">通过</option>
                            <option value="0">不通过</option>
                        </select>
                    </td>
                </tr>
                <tr style="vertical-align:top">
                    <td>
                        审核详情:
                    </td>
                    <td>
                        <textarea name="info" rows="10" cols="30"></textarea>
                    </td>
                </tr>
            </table>
        </form>
    </div>
</div>


<div id="show-book-id">
    <div align="center" style="margin-top: 30px">
        <div style="margin-bottom:20px">
            <input class="easyui-textbox" name="bookname" style="width:50%"
                   id="show-book-name"
                   data-options="label:'书籍名称:',required:true">
        </div>
        <div style="margin-bottom:20px">
            <input class="easyui-textbox" name="isbn" style="width:50%"
                   id="show-book-isbn"
                   data-options="label:'ISBN:',required:true">
        </div>
        <div style="margin-bottom:20px">
            <input class="easyui-textbox" name="price" style="width:50%"
                   id="show-book-price"
                   data-options="label:'单价:',required:true">
        </div>
        <div style="margin-bottom:20px">
            <input class="easyui-textbox" name="number" style="width:50%"
                   id="show-book-num"
                   data-options="label:'数量:',required:true,validType:'email'">
        </div>
        <div style="margin-bottom:20px">
            <input class="easyui-textbox" name="groupprice" style="width:50%"
                   id="show-book-group-price"
                   data-options="label:'团购价:',required:true">
        </div>
        <div style="margin-bottom:20px">
            <input class="easyui-textbox" name="layout" style="width:50%" data-options="label:'版次:',required:true">
        </div>
        <div style="margin-bottom:20px">
            <input class="easyui-textbox" name="register" style="width:50%"
                   data-options="label:'册数:',required:true">
        </div>
        <div style="margin-bottom:20px">
            <input class="easyui-textbox" name="weight" style="width:50%" data-options="label:'重量:',required:true">
        </div>
        <div style="margin-bottom:20px">
            <input class="easyui-textbox" name="bookintroduce" style="width:50%;height:60px"
                   id="show-book-bookintroduce"
                   data-options="label:'书籍简介:',multiline:true">
        </div>
        <div style="margin-bottom:20px">
            <input class="easyui-textbox" name="authorintroduce" style="width:50%;height:60px"
                   id="show-book-authorintroduce"
                   data-options="label:'作者简介:',multiline:true">
        </div>
        <div style="margin-bottom:20px">
            <img id="show-img-id" alt="没有对应图片" src=""></img>
        </div>
    </div>
</div>
</body>
</html>